package com.jike.noobmoney.mvp.view.activity;


import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jike.noobmoney.R;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.BaseEntity;
import com.jike.noobmoney.entity.CheckNumEntity;
import com.jike.noobmoney.entity.MoneyEntity;
import com.jike.noobmoney.entity.NewTaskListEntity;
import com.jike.noobmoney.entity.NumEntity;
import com.jike.noobmoney.mvp.presenter.UserPresenter;
import com.jike.noobmoney.net.IView;
import com.jike.noobmoney.util.AppUtils;
import com.jike.noobmoney.util.ComUtils;
import com.jike.noobmoney.util.MD5;
import com.jike.noobmoney.util.MobileInfoUtil;
import com.jike.noobmoney.util.SPUtils;
import com.jike.noobmoney.util.ToastUtils;
import com.lz.playmy.MD5Util;
import com.mdad.sdk.mduisdk.AdManager;
import com.mdad.sdk.mduisdk.MdVideoAdManager;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import java.util.Date;
import java.util.HashMap;
import com.mob68.ad.RewardVideoAd;
import com.mob68.ad.listener.IRewardVideoAdListener;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by kekex on 2019/3/28
 * 每日签到
 */

public class CheckInActivity extends BaseActivity implements IView {

//    @BindView(R.id.tv_money)
//    TextView tvMoney;
//
//    @BindView(R.id.tv_new_yaoqing)
//    TextView tvNewYaoqing;
//    @BindView(R.id.tv_new_shipin)
//    TextView tvNewShipin;
//    @BindView(R.id.tv_new_gongzhonghao)
//    TextView tvNewGongzhonghao;
//    @BindView(R.id.tv_new_renwu)
//    TextView tvNewRenwu;
     @BindView(R.id.tv_title)
     TextView tv_Title;
//    @BindView(R.id.tv_newtask3)
//    TextView tvNewRenwu3;
//    @BindView(R.id.tv_newtask6)
//    TextView tvNewRenwu6;
//
//    @BindView(R.id.tv_new_jinqun)
//    TextView tvNewJinqun;
//    @BindView(R.id.tv_invite_num)
//    TextView tvInviteNum;
        @BindView(R.id.tv_v1money)
       TextView tv_v1money;
       @BindView(R.id.tv_v1number)
       TextView tv_v1number;
       @BindView(R.id.tv_v1sumnumber)
       TextView tv_v1sumnumber;

       @BindView(R.id.tv_v2money)
       TextView tv_v2money;
       @BindView(R.id.tv_v2number)
       TextView tv_v2number;
       @BindView(R.id.tv_v2sumnumber)
       TextView tv_v2sumnumber;

       @BindView(R.id.tv_v3money)
       TextView tv_v3money;
       @BindView(R.id.tv_v3number)
       TextView tv_v3number;
       @BindView(R.id.tv_v3sumnumber)
       TextView tv_v3sumnumber;
       @BindView(R.id.tv_v4money)
       TextView tv_v4money;
       @BindView(R.id.tv_v4number)
       TextView tv_v4number;
       @BindView(R.id.tv_v4sumnumber)
       TextView tv_v4sumnumber;

       @BindView(R.id.tv_v5money)
       TextView tv_v5money;

       @BindView(R.id.tv_v5number)
       TextView tv_v5number;
       @BindView(R.id.tv_v5sumnumber)
       TextView tv_v5sumnumber;


       @BindView(R.id.tv_video1)
       TextView tv_video1;

       @BindView(R.id.tv_video2)
       TextView tv_video2;
       @BindView(R.id.tv_littlegame)
       TextView tv_littlegame;

       @BindView(R.id.tv_news)
       TextView tv_news;

       @BindView(R.id.tv_applets)
       TextView tv_applets;

    @BindView(R.id.ll_challenge)
    LinearLayout ll_challenge;
    @BindView(R.id.ll_check_in)
    ImageView llCheckIn;


    private UserPresenter userPresenter;
    private String userid;



    private int invite = -1;
    private int video = -1;
    private int attention = -1;
    private int complete = -1;
    private int team = -1;
    private int complete3;
    private int complete6;

    public String deviceno;



    @Override
    protected int layoutResID() {
        return R.layout.activity_check_in_layout;
    }

    @Override
    protected void initData() {
        userPresenter = new UserPresenter(this);
        userid = SPUtils.getInstance().getString(ConstantValue.SpType.userid);
        tv_Title.setText("每日签到");
        AdManager.getInstance(this).init(this, ConstantValue.appId, userid, ConstantValue.key, "");
        refreshData();
//            newTaskList();
        deviceno= MobileInfoUtil.getIMEI(context);
    }


    /**
     * 获取完成情况
     */
    private void refreshData() {
        showProgress();
        userPresenter.getCheckNum(userid, ConstantValue.RequestKey.getCheckNum);
    }

    /**
     * 表示广告已经看完了
     */
    private void updateData() {
        showProgress();
        userPresenter.moneyView(userid, ConstantValue.RequestKey.updateView);
    }

    /**
     * 获取新手任务列表
     */
    private void newTaskList() {
        showProgress();
        userPresenter.newusertasklist(userid, ConstantValue.RequestKey.new_task_list);
    }

    /**
     * 上传视频回调
     */
    private void updateView(String userid,String deviceno,Integer type,Integer ischeck,long time) {
        showProgress();
        String key = "f52jh4l1h42hgna31m";
        String sign= MD5.GetMD5Code(userid+""+deviceno+""+type+""+ischeck+""+time+key,true);
        userPresenter.callbackVideo(userid,deviceno,type,ischeck,time,sign, ConstantValue.RequestKey.viedo_check);
    }

    RewardVideoAd  mRVad;

    RewardVideoAd  mRVad1;

    @Override
    public boolean ismain() {
        return true;
    }
    @Override
    public Boolean isfits() {
        return true;
    }

    @OnClick({R.id.ll_challenge,R.id.ll_task, R.id.game_center,R.id.iv_back,R.id.ll_check_in
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_new_yaoqing:
                switch (invite) {
                    case 0:
                        //未完成  去邀请好友
                        recommend();
                        break;
                    case 1:
                        //完成
                        lingqu("1");
                        break;
                }
                break;
            case R.id.tv_new_shipin:
                switch (video) {
                    case 0:
                        //未完成  看视频
                        Intent intent = new Intent(context, VideoTwoActivity.class);
                        intent.putExtra("isTask", true);
                        startActivityForResult(intent, 201);
                        break;
                    case 1:
                        //完成
                        lingqu("2");
                        break;
                }
                break;
            case R.id.tv_new_gongzhonghao:
                switch (attention) {
                    case 0:
                        //未完成
                        GuanzhuActivity.startAct(this, 1);
                        break;
                    case 1:
                        //完成
                        lingqu("3");
                        break;
                }
                break;
            case R.id.tv_new_renwu:
                switch (complete) {
                    case 0:
                        //未完成
                        setResult(RESULT_OK);
                        finish();
                        break;
                    case 1:
                        //完成
                        lingqu("4");
                        break;
                }
                break;

            case R.id.tv_newtask3:
                switch (complete3) {
                    case 0:
                        //未完成
                        setResult(RESULT_OK);
                        finish();
                        break;
                    case 1:
                        //完成
                        lingqu("6");
                        break;
                }
                break;

            case R.id.tv_newtask6:
                switch (complete6) {
                    case 0:
                        //未完成
                        setResult(RESULT_OK);
                        finish();
                        break;
                    case 1:
                        //完成
                        lingqu("7");
                        break;
                }
                break;
            case R.id.tv_new_jinqun:
                switch (team) {
                    case 0:
                        //未完成
                        GuanzhuActivity.startAct(this, 2);
                        break;
                    case 1:
                        //完成
                        lingqu("5");
                        break;
                }
                break;


            //----------------------------------------------------------------------
            case R.id.iv_video:
                //新手教程voide
                Intent intent = new Intent(context, VideoTwoActivity.class);
                intent.putExtra("isTask", false);
                startActivity(intent);
                break;
            case R.id.iv_qqqun:
                //QQ群
                ComUtils.startQQ(context, 3, "564104407");
                break;
            case R.id.iv_gzh:
                //GuanzhuActivity.startAct(this, 3);
               // ComUtils.startQQ(context, 3, "739414363");
                ComUtils.startQQ(context, 3, "736856485");
                break;
            case R.id.iv_back:
                finish();
                break;
            case R.id.ll_challenge:
                startActivity(new Intent(context,ChallengeActivity.class));
                break;
            case R.id.ll_task:
                startActivity(new Intent(context,TastListActivity.class));
                break;
            case R.id.game_center:
                startActivity(new Intent(context,GameCenterActivity.class));
                break;
            case R.id.ll_check_in:
//                if (llCheckIn.isSelected()) {
//                    checkIn();
//                } else {
//                    ToastUtils.showShortToastSafe("今天已经签到了,明天再来吧~");
//                }
             //   checkIn();

                if (AppUtils.isFastClick()) {
                    return;
                }

                String lastTime = SPUtils.getInstance().getString(ConstantValue.SpType.day1, "2019-03-11");
                String nowTime = ComUtils.getDay();
                if (nowTime.equals(lastTime)) {
                    ToastUtils.showShortToast("今日已播放完毕，下次再来");
                } else {
                mRVad1 = new RewardVideoAd(CheckInActivity.this, "2118","3175","IRaazkio",new IRewardVideoAdListener() {
                    @Override
                    public void onAdSuccess() {
                        if (mRVad1.isReady()) {
                            mRVad1.showAd("3175");

                        }else {
                            Toast.makeText(CheckInActivity.this, "请稍后", Toast.LENGTH_LONG).show();
                        }
                    }
                    @Override
                    public void onAdFailed(String s) {
                        printStatusMsg("视频onAdFailed");
                    }
                    @Override
                    public void onAdClick(long l) {
                        printStatusMsg("视频onAdClick.");
                    }
                    @Override
                    public void onVideoPlayStart() {
                        printStatusMsg("视频onVideoPlayStart.");
                    }
                    @Override
                    public void onVideoPlayComplete() {
                        printStatusMsg("视频onVideoPlayComplete.");

                        SPUtils.getInstance().put(ConstantValue.SpType.day1, ComUtils.getDay());
                        updateView(userid,deviceno,1,1,System.currentTimeMillis()/1000);
                    }
                    @Override
                    public void onVideoPlayError(String s) {
                        printStatusMsg("视频onAdClick.");
                    }
                    @Override
                    public void onVideoPlayClose(long l) {
                        printStatusMsg("视频onVideoPlayClose.");
                    }
                    @Override
                    public void onAdPreSuccess() {
                        printStatusMsg("视频onAdPreSuccess.");
                    }
                    @Override
                    public void onLandingPageOpen() {
                        printStatusMsg("视频onLandingPageOpen.");
                    }
                    @Override
                    public void onLandingPageClose() {
                        printStatusMsg("视频onLandingPageClose.");
                    }
                    @Override
                    public void onReward(HashMap<String, String> hashMap) {
                        printStatusMsg("视频奖励："+hashMap.toString());
                        /**
                         * TODO 注意：只能在收到 onReward 回调的时候才能给予用户奖励。
                         */
                        //*
                        AlertDialog alertDialog = new AlertDialog.Builder(CheckInActivity.this)
                                .setCancelable(false)
                                .setTitle("获取奖励提示")
                                .setMessage("完成任务、恭喜成功获取一次免费复活机会")
                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                    }
                                })
                                .create();
                        alertDialog.show();
                    }
                });
                }
                break;
            case R.id.ll_v2:
                MdVideoAdManager mdVideoAdManager   = new MdVideoAdManager(this);
                mdVideoAdManager.loadAd(new MdVideoAdManager.MdAdListener() {
                    @Override
                    public void onAdComplete() {
                        updateView(userid,deviceno,2,0,System.currentTimeMillis()/1000);
                    }

                    @Override
                    public void onAdClose() {
                    }

                    @Override
                    public void onNoAd() {

                    }

                    @Override
                    public void onAdPrepare() {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mdVideoAdManager.show();
                            }
                        });

                    }

                    @Override
                    public void onAdClick() {

                    }

                    @Override
                    public void onVideoShow() {
                    }

                    @Override
                    public void onAdExreaClick() {

                    }
                });
                break;
            case R.id.ll_v5:
//                AdManager.getInstance(context).setBackGroundColor("#FFE148"); //标题栏背景色
//                AdManager.getInstance(context).setWeChatTaskTitle("小程序");//小程序标题
//                AdManager.getInstance(context).openWeChatTaskSetList(context);
                break;
            case R.id.ll_v1:
//                mRVad = new RewardVideoAd(CheckInActivity.this, "2118","3175","IRaazkio",new IRewardVideoAdListener() {
//                    @Override
//                    public void onAdSuccess() {
//                        if (mRVad.isReady()) {
//                            mRVad.showAd("3175");
//
//                        }else {
//                            Toast.makeText(CheckInActivity.this, "请稍后", Toast.LENGTH_LONG).show();
//                        }
//                    }
//                    @Override
//                    public void onAdFailed(String s) {
//                        printStatusMsg("视频onAdFailed");
//                    }
//                    @Override
//                    public void onAdClick(long l) {
//                        printStatusMsg("视频onAdClick.");
//                    }
//                    @Override
//                    public void onVideoPlayStart() {
//                        printStatusMsg("视频onVideoPlayStart.");
//                    }
//                    @Override
//                    public void onVideoPlayComplete() {
//                        printStatusMsg("视频onVideoPlayComplete.");
//                        updateView(userid,deviceno,1,0,System.currentTimeMillis()/1000);
//                    }
//                    @Override
//                    public void onVideoPlayError(String s) {
//                        printStatusMsg("视频onAdClick.");
//                    }
//                    @Override
//                    public void onVideoPlayClose(long l) {
//                        printStatusMsg("视频onVideoPlayClose.");
//                    }
//                    @Override
//                    public void onAdPreSuccess() {
//                        printStatusMsg("视频onAdPreSuccess.");
//                    }
//                    @Override
//                    public void onLandingPageOpen() {
//                        printStatusMsg("视频onLandingPageOpen.");
//                    }
//                    @Override
//                    public void onLandingPageClose() {
//                        printStatusMsg("视频onLandingPageClose.");
//                    }
//                    @Override
//                    public void onReward(HashMap<String, String> hashMap) {
//                        printStatusMsg("视频奖励："+hashMap.toString());
//                        /**
//                         * TODO 注意：只能在收到 onReward 回调的时候才能给予用户奖励。
//                         */
//                        //*
//                        AlertDialog alertDialog = new AlertDialog.Builder(CheckInActivity.this)
//                                .setCancelable(false)
//                                .setTitle("获取奖励提示")
//                                .setMessage("完成任务、恭喜成功获取一次免费复活机会")
//                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                                    @Override
//                                    public void onClick(DialogInterface dialog, int which) {
//                                        dialog.dismiss();
//                                    }
//                                })
//                                .create();
//                        alertDialog.show();
//                    }
//                });
                break;
            case R.id.ll_v3:
//                Intent intent_game =new Intent(context,GameListActivity.class);
//                startActivity(intent_game);
                break;


        }
    }
    public void  printStatusMsg(String msg){
       // Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
    }

    /**
     * 签到
     */
    private void checkIn() {
        showProgress();
        userPresenter.checkin(userid, ConstantValue.RequestKey.checkIn);
    }

    /**
     * 点击分享
     */
    public void recommend() {
        String recode = SPUtils.getInstance().getString(ConstantValue.SpType.recode);//签到页
        String taskurl = SPUtils.getInstance().getString(ConstantValue.SpType.taskurl);
        String url = !TextUtils.isEmpty(taskurl) ? taskurl + "?recode=" + recode : ConstantValue.COMMENTURLCOPY + recode;
        UMWeb web = new UMWeb(url);
        web.setTitle("小白赚钱");
        web.setThumb(new UMImage(context, R.mipmap.ic_launcher));
        web.setDescription(getString(R.string.text_yaoqing1));
        ShareAction shareAction = new ShareAction(this);
        shareAction.withMedia(web);
        shareAction.setDisplayList(SHARE_MEDIA.QZONE, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE);
        shareAction.open();
    }


    private void lingqu(String flag) {
        if (AppUtils.isFastClick()) {
            ToastUtils.showShortToastSafe("操作有点频繁,稍后重试");
            return;
        }
        showProgress();
        userPresenter.checkinreceive(userid, flag, ConstantValue.RequestKey.check_new_task_receive);
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        dismissProgress();
        if (ConstantValue.RequestKey.updateView.equals(actionType)) {
//            //获取用户余额
//            MoneyEntity.UserBean userBean = (MoneyEntity.UserBean) data;
//            tvMoney.setText("" + userBean.getMoney());
            //上传视频信息后
        }
//        任务完成情况数据
        if (ConstantValue.RequestKey.getCheckNum.equals(actionType)) {
            CheckNumEntity bean=(CheckNumEntity) data;
            //获取任务完成情况
            tv_v1money.setText(bean.v1money+"");
            tv_v1number.setText(""+bean.v1number);
            tv_v1sumnumber.setText(""+bean.v1sumnumber);



            tv_v2money.setText(bean.v2money+"");
            tv_v2number.setText(""+bean.v2number);
            tv_v2sumnumber.setText(""+bean.v2sumnumber);


            tv_v3money.setText(bean.lgmoney+"");
            tv_v3number.setText(""+bean.lgnumber);
            tv_v3sumnumber.setText(""+bean.lgsumnumber);

            tv_v4money.setText(bean.newsmoney+"");
            tv_v4number.setText(""+bean.newsnumber);
            tv_v4sumnumber.setText(""+bean.newssumnumber);

            tv_v5money.setText(bean.amoney+"");
            tv_v5number.setText(""+bean.anumber);
            tv_v5sumnumber.setText(""+bean.asumnumber);


            refreshNewView(tv_video1,bean.video1);
            refreshNewView(tv_video2,bean.video2);
            refreshNewView(tv_littlegame,bean.littlegame);
            refreshNewView(tv_news,bean.news);
            refreshNewView(tv_applets,bean.applets);

        }
        if (ConstantValue.RequestKey.viedo_check.equals(actionType)) {
            ToastUtils.showShortToast("观看视频奖励发放成功！");

        }

        if (ConstantValue.RequestKey.new_task_receive.equals(actionType)) {
            ToastUtils.showShortToastSafe(msg);
            //领取成功
            newTaskList();
            refreshData();
        }
        if (ConstantValue.RequestKey.checkIn.equals(actionType)) {
            ToastUtils.showShortToast(msg);
            long checkinTime = System.currentTimeMillis();
            SPUtils.getInstance().put("checkin_time", checkinTime);

            SPUtils.getInstance().put(ConstantValue.SpType.day, ComUtils.getDay());
            changeState(false); //签到成功
        }

        if (ConstantValue.RequestKey.check_new_task_receive.equals(actionType)) {
            ToastUtils.showShortToastSafe(msg);
            //领取成功
            refreshData();
        }

    }

    private void changeState(boolean isAbleQiandao) {
        if (isAbleQiandao) {
            //可以签到
            llCheckIn.setSelected(true);

        } else {
            //不可签到
            llCheckIn.setSelected(false);
        }

    }

    private void refreshNewView(TextView textView, int status) {
        switch (status) {
            case 0:
                //未完成
                textView.setText("去完成");
                switch (textView.getId())
                {
                    case R.id.tv_video1:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (AppUtils.isFastClick()) {
                                    return;
                                }
                                mRVad = new RewardVideoAd(CheckInActivity.this, "2118","3175","IRaazkio",new IRewardVideoAdListener() {
                                    @Override
                                    public void onAdSuccess() {
                                        if (mRVad.isReady()) {
                                            mRVad.showAd("3175");

                                        }else {
                                            Toast.makeText(CheckInActivity.this, "请稍后", Toast.LENGTH_LONG).show();
                                        }
                                    }
                                    @Override
                                    public void onAdFailed(String s) {
                                        printStatusMsg("视频onAdFailed");
                                    }
                                    @Override
                                    public void onAdClick(long l) {
                                        printStatusMsg("视频onAdClick.");
                                    }
                                    @Override
                                    public void onVideoPlayStart() {
                                        printStatusMsg("视频onVideoPlayStart.");
                                    }
                                    @Override
                                    public void onVideoPlayComplete() {
                                        printStatusMsg("视频onVideoPlayComplete.");
                                        updateView(userid,deviceno,1,0,System.currentTimeMillis()/1000);
                                    }
                                    @Override
                                    public void onVideoPlayError(String s) {
                                        printStatusMsg("视频onAdClick.");
                                    }
                                    @Override
                                    public void onVideoPlayClose(long l) {
                                        printStatusMsg("视频onVideoPlayClose.");
                                    }
                                    @Override
                                    public void onAdPreSuccess() {
                                        printStatusMsg("视频onAdPreSuccess.");
                                    }
                                    @Override
                                    public void onLandingPageOpen() {
                                        printStatusMsg("视频onLandingPageOpen.");
                                    }
                                    @Override
                                    public void onLandingPageClose() {
                                        printStatusMsg("视频onLandingPageClose.");
                                    }
                                    @Override
                                    public void onReward(HashMap<String, String> hashMap) {
                                        printStatusMsg("视频奖励："+hashMap.toString());
                                        /**
                                         * TODO 注意：只能在收到 onReward 回调的时候才能给予用户奖励。
                                         */
                                        //*
                                        AlertDialog alertDialog = new AlertDialog.Builder(CheckInActivity.this)
                                                .setCancelable(false)
                                                .setTitle("获取奖励提示")
                                                .setMessage("完成任务、恭喜成功获取一次免费复活机会")
                                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                    }
                                                })
                                                .create();
                                        alertDialog.show();
                                    }
                                });
                            }
                        });
                        break;
                    case R.id.tv_video2:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (AppUtils.isFastClick()) {
                                    return;
                                }
                                MdVideoAdManager mdVideoAdManager   = new MdVideoAdManager(context);
                mdVideoAdManager.loadAd(new MdVideoAdManager.MdAdListener() {
                    @Override
                    public void onAdComplete() {
                        updateView(userid,deviceno,2,0,System.currentTimeMillis()/1000);
                    }

                    @Override
                    public void onAdClose() {
                    }

                    @Override
                    public void onNoAd() {

                    }

                    @Override
                    public void onAdPrepare() {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mdVideoAdManager.show();
                            }
                        });

                    }

                    @Override
                    public void onAdClick() {

                    }

                    @Override
                    public void onVideoShow() {
                    }

                    @Override
                    public void onAdExreaClick() {

                    }
                });
                            }
                        });
                        break;
                    case R.id.tv_littlegame:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (AppUtils.isFastClick()) {
                                    return;
                                }
                                Intent intent_game =new Intent(context,GameListActivity.class);
                                startActivity(intent_game);
                               // ToastUtils.showShortToast("该功能尚未开放，敬请期待");
                            }
                        });
                        break;
                    case R.id.tv_news:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (AppUtils.isFastClick()) {
                                    return;
                                }
                                ToastUtils.showShortToast("该功能尚未开放，敬请期待");
                            }
                        });
                        break;
                    case R.id.tv_applets:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (AppUtils.isFastClick()) {
                                    return;
                                }
                                AdManager.getInstance(context).setBackGroundColor("#FFE148"); //标题栏背景色
                                AdManager.getInstance(context).setWeChatTaskTitle("小程序");//小程序标题
                                AdManager.getInstance(context).openWeChatTaskSetList(context);
                            }
                        });
                        break;

                }
                break;
            case 1:
                //完成
                textView.setText("领取奖励");
                switch (textView.getId())
                {
                    case R.id.tv_video1:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                lingqu("1");
                            }
                        });
                        break;
                    case R.id.tv_video2:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                lingqu("2");
                            }
                        });
                        break;
                    case R.id.tv_littlegame:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                lingqu("3");
                            }
                        });
                        break;
                    case R.id.tv_news:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                lingqu("4");
                            }
                        });
                        break;
                    case R.id.tv_applets:
                        textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                lingqu("5");
                            }
                        });
                        break;

                }
                break;
            case 2:
                //已领取
                textView.setText("已领取");
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                    }
                });
                break;

        }
    }


    @Override
    public void onFailed(String code, String msg) {
        ToastUtils.showShortToast(msg);
        dismissProgress();
    }
    @Override
    public void onResume()
    {
        super.onResume();
        refreshData();
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 201 && resultCode == RESULT_OK) {
            newTaskList();
        }
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        AdManager.getInstance(this).onAppExit();
    }



}
